<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="/WEB-INF/tlds/authorizetag.tld" prefix="px"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>广告</title>
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet">
<link href="/admin/public/animate.css" rel="stylesheet">
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />
<!-- 时间控件样式 -->
<link
	href="/admin/css/plugins/datetimepicker/bootstrap-datetimepicker.min.css"
	rel="stylesheet" media="screen">
<link href="/admin/public/animate.css" rel="stylesheet">
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/templet_form.css" />
<link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
<!-- 高德地图 -->
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<!-- 本地 -->
<script type="text/javascript"src="http://webapi.amap.com/maps?v=1.3&key=064fca579fe2d6c213c9c416d17b0a60&plugin=AMap.Autocomplete"></script>
    

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<style type="text/css">
.img{
	height: 202px;
	width:640px;
}
</style>
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<!-- 添加 -->
						<c:if test="${(empty AdverId)}" >
							<form class="form-horizontal" method="post" id="addClient"
							novalidate="novalidate" enctype="multipart/form-data">
						</c:if>
						<!-- 修改 -->
						<c:if test="${!(empty AdverId)}" >
							<form class="form-horizontal" method="post" id="upClient" 
							novalidate="novalidate" enctype="multipart/form-data" >
							<input type="hidden" name="AdverId" id="AdverId"
								value="${AdverId }">
							<input type="hidden" name="oldImgUrl" id="oldImgUrl"
								value="${ImgUrl }">
						</c:if>
							<div class="form-group">
								<label class="col-lg-2 control-label">广告名称:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="AdName"
										name="AdName" value="${AdName }" >
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">到期时间:</label>
								<div class="col-lg-6">
									<div class="date input-append form_date ymd_date"
										id="addtimeCalendar" style="float: left; margin-right: 5px;">
										<div class="input-group">
											<input class="form-control input-sm" type="text"
												name="ExpireDate" id="ExpireDate" value="<fmt:formatDate value="${ExpireDate }" pattern="yyyy-MM-dd"/>"> <span
												class="add-on input-group-addon"
												style="position: relative; left: -40px;"> <i
												class="fa fa-calendar" style="color: black;"></i>
											</span>
										</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">图片:</label>
								<div class="col-lg-6">
									<input type="file" class="form-control" id="ImgUrl"
										name="ImgUrl"  onchange="preview(this,1)">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<span style="color:red;">建议图片尺寸：640*202</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<div id="preview1">
										<img alt="" src="${ImgUrl}">
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">链接地址:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="LinkUrl"
										name="LinkUrl" value="${LinkUrl }">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">加入时间:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="InputDate"
										name="InputDate" value="<fmt:formatDate value="${InputDate }" pattern="yyyy-MM-dd"/>" readonly="readonly">
									
								</div> 
							</div>
							<c:if test="${(empty AdverId)}" >
								<px:authorize setting="广告-添加广告信息">
									<input type="button" onclick="add();" style="display: none;" id="tijiao" value="添加"/>
								</px:authorize>
							</c:if> 
							<c:if test="${!(empty AdverId)}" >
								<px:authorize setting="广告-修改广告信息">
									<input type="button" onclick="up();" style="display: none;" id="tijiao" value="修改" />
								</px:authorize>
							</c:if> 
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<!-- 选择框 -->
		<script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
	<!-- 时间控件样式 -->
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker.min.js"></script>
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker-update.min.js"></script>
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
	<script type="text/javascript">
	$('.i-checks').iCheck({
		checkboxClass: 'icheckbox_square-green',
		radioClass: 'iradio_square-green',
	});
		function preview(file, i) {
			var prevDiv = document.getElementById('preview' + i);
			if (file.files && file.files[0]) {
				var reader = new FileReader();
				reader.onload = function(evt) {
					prevDiv.innerHTML = '<img class="img" src="' + evt.target.result + '" />';
				}
				reader.readAsDataURL(file.files[0]);
			} else {
				prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
			}
		}
	</script>
	<script type="text/javascript">
	$(function(){
		$('.ymd_date').datetimepicker({　
			minView: "month",
			format: "yyyy-mm-dd",
			language: 'zh-CN',
			autoclose: true,
			pickerPosition: "bottom-left",
			
		});
	})
	
		function check(){
			var AdName = $("#AdName").val();
			var ExpireDate = $("#ExpireDate").val();
			var ImgUrl = $("#ImgUrl").val();
			var InputDate = $("#InputDate").val();
			//var LinkUrl = $("#LinkUrl").val();
			if(AdName==null || AdName==''){
				alertNew("请输入广告名称！", false);
				return false;
			}
			if(ExpireDate==null || ExpireDate==''){
				alertNew("请选择到期时间！", false);
				return false;
			} 
			if(InputDate==null || InputDate==''){
				if(ImgUrl==null || ImgUrl==''){
					alertNew("请上传图片！", false);
					return false;
				}
			}
			/* if(LinkUrl==null || LinkUrl==''){
				alertNew("请输入链接地址！", false);
				return false;
			} */
			return true;
			
		}
		//添加广告
		function add() { 
			if(check()){
			     var formData = new FormData($( "#addClient" )[0]);  
			     $.ajax({  
			          url: '/admin/adver/addAdver' ,  
			          type: 'POST',  
			          data: formData,  
			          async: false,  
			          cache: false,  
			          contentType: false,  
			          processData: false,  
			          success: function (data) {  
			        	  if (data.success) {
								window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,{onOk:function(){ 
									$('#ifr', window.parent.document).attr('src',
									'/admin/adver/list');
						  		}})
							}else{
								alertNew(data.msg, false);
							}
			          },  
			          error: function (data) {  
			        	  alert("很抱歉，未知的错误发生了！");
			          }  
			     });  
			}
		}
		//修改广告
		function up() { 
			if(check()){
			     var formData = new FormData($( "#upClient" )[0]);  
			     $.ajax({  
			          url: '/admin/adver/updateAdver' ,  
			          type: 'POST',  
			          data: formData,  
			          async: false,  
			          cache: false,  
			          contentType: false,  
			          processData: false,  
			          success: function (data) {  
			        	  if (data.success) {
								window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,{onOk:function(){ 
									$('#ifr', window.parent.document).attr('src',
									'/admin/adver/list');
						  		}})
							}else{
								alertNew(data.msg, false);
							}
			          },  
			          error: function (data) {  
			        	  alert("很抱歉，未知的错误发生了！"); 
			          }  
			     }); 
			}
		}
		
	</script>
	
</body>
</html>